var ns;
var app = new Vue({
    el: '#app',
    data: {
        ismoreshow: false,
        form: {
            ID: 0,
            imagelist: [],
            processlist: [],
        },
        pingjialist:[],
        task_imgList: [],
        total: false,
        isviewdetail: true,
        num: 6,
    },
    methods: {
        get_data: function() {
            var that = this;
            var options = {};
            //alert(that.form.ID);
            options.ID = that.form.ID;
            options.action = "getnewservicedetail";
            ns.post(options, function(succeed, data, err) {

                console.log(JSON.stringify(data));
                if (succeed) {
                    //  alert(JSON.stringify(data));
                    that.form = data.form;
                    that.task_imgList = data.form.imagelist;
                     // 评价  获取评价数据  接口
                     that.pingjialist = data.form.pingjialist.rows;
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        tel_phone: function(item) {
            api.call({
                type: 'tel_prompt',
                number: item.phonenumber
            });
        },
        img_browser: function(item) {
            var that = this;
            var imgurls = [];
            imgurls.push(item.imgurl);
            imageBrowser.openImages({
                imageUrls: imgurls,
                showList: false,
                activeIndex: 0
            });
        },
        open_bsbxpingjia: function() {
            var that = this;
            ns.openWin('dl_bsbxpingjia', '用户评价', {
                id: that.form.ID,
            });
        },
        // 星星 显示 目前只显示单条星星 
        show_star: function () {
            var that = this;
            var data = that.pingjialist;
            if (data.length > 0) {
                for (var j = 0; j < data.length; j++) {
                    //星星值 字段 int 类型
                    if (data[j].RateStar > 0) {
                        for (var i = 0; i < data[j].RateStar; i++) {
                            var Index = i + 1;
                            $("#rater-" + Index).addClass("rater-star-item-current");
                            if (Index == 4) {
                                $("#rater-" + Index).addClass("rater-star-happy");
                            }
                            if (Index > 4) {
                                $("#rater-" + Index).addClass("rater-star-full");
                            }

                        }
                    }
                }
            }
        },
        dateFormat: function (datetime1) {
            var datetime = new Date(datetime1);
            this.year = datetime.getFullYear();
            this.month = datetime.getMonth() + 1;
            this.date = datetime.getDate();
            this.hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
            this.minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
           // this.second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
           // this.milliSeconds = datetime.getMilliseconds();
            var currentTime = this.year + '-' + this.month + '-' + this.date + ' ' + this.hour + ':' + this.minute; //  + ':' + this.second+ '.' + this.milliSeconds
            return currentTime;
        },

    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    imageBrowser = api.require('imageBrowser');
    app.form.ID = api.pageParam.id || 0;
    toast = new auiToast();
    app.get_data();
    api.addEventListener({
        name: 'reload_pingjialist'
    }, function(ret, err) {
        if (ret) {
            app.get_data();
        }
    });
};
